package com.neutech.service.impl;

import com.neutech.dao.RegisterUserDAO;
import com.neutech.dao.UserDAO;
import com.neutech.dao.impl.RegisterUserDAOImpl;
import com.neutech.dao.impl.UserDAOImpl;
import com.neutech.entity.User;
import com.neutech.service.RegisterUserService;
import com.neutech.vo.ResultVO;

import java.util.List;

public class RegisterUserServiceImpl implements RegisterUserService {

    private RegisterUserDAO registerUserDAO =new RegisterUserDAOImpl();
    private UserDAO userDAO = new UserDAOImpl();

    @Override
    public ResultVO add(String userName, String password) {
        List<User> users = userDAO.getAllUser();
        for (User user : users) {
            if (user.getUsername().equals(userName)) {
                return ResultVO.error(2003,"用户已存在");
            }
        }

        registerUserDAO.AddUser(userName,password);
        return ResultVO.success("注册成功");
    }
}
